<?php defined('In33hao') or exit('Access Invalid!');?>

<div class="login-layout">
  <div class="top">
    <h2><?php echo $lang['login_index_title_02'];?></h2>
    <h6><?php echo $lang['login_index_title_03'];?></h6>
  </div>
  <form method="post" id="form_login" action="./index.php?act=login&op=checkLogin">
    <?php Security::getToken();?>
    <input type="hidden" name="form_submit" value="ok" />
    <input type="hidden" name="SiteUrl" id="SiteUrl" value="<?php echo SHOP_SITE_URL;?>" />
    <div class="lock-holder">
      <div class="form-group pull-left input-username">
        
          <label>手机</label>
          <input name="user_name" id="mobile" autocomplete="off" type="text" class="input-text" value="" required>
          
      </div>
      <i class="fa fa-ellipsis-h dot-left"></i> <i class="fa fa-ellipsis-h dot-right"></i>
      <div class="form-group pull-right input-password-box">
          <label>验证</label>
<!--          <input name="password" id="password" class="input-text" autocomplete="off" type="password" required pattern="[\S]{6}[\S]*" title="--><?php //echo $lang['login_index_password_pattern'];?><!--">-->
        <span>
      <div class="code">
        <div class="arrow"></div>
        <div class="code-img"><img src="index.php?act=seccode&op=makecode&admin=1&nchash=<?php echo getNchash();?>" name="codeimage" id="codeimage" border="0"/></div>
        <a href="JavaScript:void(0);" id="hide" class="close" title="<?php echo $lang['login_index_close_checkcode'];?>"><i></i></a><a href="JavaScript:void(0);" onclick="javascript:document.getElementById('codeimage').src='index.php?act=seccode&op=makecode&admin=1&nchash=<?php echo getNchash();?>&t=' + Math.random();" class="change" title="<?php echo $lang['login_index_change_checkcode'];?>"><i></i></a> </div>
      <input name="captcha" type="text" required class="input-text" id="captcha" placeholder="<?php echo $lang['login_index_checkcode'];?>" pattern="[A-z0-9]{4}" title="<?php echo $lang['login_index_checkcode_pattern'];?>" autocomplete="off" value="" >
      </span>
      </div>
    </div>
    <div class="avatar"><img src="<?php if (cookie('admin_avatar') == '') {echo ADMIN_TEMPLATES_URL. '/images/login/admin.png';} else { echo UPLOAD_SITE_URL . '/' . ATTACH_ADMIN_AVATAR . '/' . cookie('admin_avatar');}?>" alt=""></div>
    <div class="submit"> <span>
        <input name="nchash" type="hidden" id="nchash" value="<?php echo getNchash();?>" />
        <input name="admin_id" type="hidden" id="admin" value="<?php echo getNchash();?>" />
        <input name="auth_code" style="display: none" type="text" required class="input-code" id="auth_code" autocomplete="off" value="" >
        <input name="" class="input-button send_code" type="button" value="发送验证码">
      <input name="" style="display: none" class="input-button btn-submit" id="buttom" type="button" value="<?php echo $lang['login_index_button_login'];?>">
      </span> </div>
    <div class="tips_box">
         <div class="tips_box_error_check">
              <i></i>验证码错误
         </div>
         <div class="send_time_success">
              <i></i>短信验证码已发送 <span id="timedown">60</span> s
         </div>
    </div>
      <div class="submit2"></div>
  </form>
</div>
<script>
    $(".send_code").click(function(){
      var mobile = $("#mobile").val();
      var captcha = $("#captcha").val();
      if(mobile==''){
          doTime($(this),'手机号不能为空');
          return;
      }
      var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
      if (!myreg.test(mobile)){
        doTime($(this),'请填写正确的手机号码');
        return;
      }

      // 验证码验证
      var nash = $("#nchash").val();
      if (captcha==''){
        doTime($(this),'验证码不能为空');
        return;
      }
      $this = $(this);
      $.ajax({
         type:"POST",
         url:'./index.php?act=login&op=checkcaptcha',
         data:{nchash:nash,captcha:captcha},
         dataType:"json",
         success:function(data){
               if(data==true){
                  sendSmsCode($this,mobile);
               }else{
                 doTime($this,'验证码错误');
               }
         }
      })
    })

    /**
     * 发送短信验证码
     * @pargam mobile 手机号
     * */
    function sendSmsCode(_this,mobile){
         if(mobile==''){
              return;
         }
         $.ajax({
             type:"POST",
             url:"./index.php?act=login&op=sendsmscode",
             data:{mobile:mobile},
             dataType:'json',
             success:function(data){
                 if(data['status']==200){
                      _this.animate({'width':0,'opacity':0},'slow');
                      setTimeout(function(){
                        $("#auth_code").fadeIn('slow');
                        $("#buttom").fadeIn('slow');
                      },600)
                      doSendTimeDown(_this);
                      $("#admin").val(data['admin_id']);
                 }else{
                      doTime(_this,'该手机号不存在');
                 }
             }
         })
    }

    function doSendTimeDown(_this){
        var timer = null;
        $(".send_time_success").animate({'opacity':1,'top':15});
        var time = 60;
        timer = setInterval(function(){
              if(time==0){
                  $("#auth_code").fadeOut('slow');
                  $("#buttom").fadeOut('slow');
                  clearInterval(timer);
                  _this.animate({'width':100,'opacity':1},'slow');
                  $(".send_time_success").animate({'opacity':0,'top':60});
                  return;
              }
              time--;
              $("#timedown").html(time)
        },1000)
    }

    /**
     * 计时开始
     */
    function doTime(_this,html){
        _this.animate({'opacity':0});
        $(".tips_box_error_check").html(' <i></i>'+html)
        $(".tips_box_error_check").animate({'opacity':1,'top':0});
        setTimeout(function(){
          _this.animate({'opacity':1});
          $(".tips_box_error_check").animate({'opacity':0,'top':60});
        },3000)
    }
</script>